package com.ymttest.database.mongo.jproduct;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.ymt.database.MongoDBDriver;
import com.ymttest.database.mongo.YmtMongoDriverFactroy;
import com.ymttest.utils.MapUtil;

public class CatalogsWapper {
	private MongoDBDriver mdd = YmtMongoDriverFactroy.getInstance_YmtProductDBdriverNewJava("Catalogs");
	
	public List<Map> getByProductId(String productId) throws Exception {
		List<Map> list = mdd.selectPartLimitToMap("{\"spid\":\"" + productId + "\"}",1);
	    return list;
	}
	
	
	public List<Map> getAllByProductId(String productId) throws Exception {
		List<Map> list = mdd.selectPartLimitToMap("{\"spid\":\"" + productId + "\"}",50);
	    return list;
	}
	
	public Map<String,Object> getByCatalogId(String catalogId) throws Exception {
		ArrayList<Map> list = mdd.selectPartLimitToMap("{\"cid\":\"" + catalogId + "\"}",1);
	    return list.size()>0?list.get(0):null;
	}
	
	
	public int getCountByProductId(String productId) throws Exception{
		return mdd.selectPartLimitToMap("{\"spid\":\"" + productId + "\"}",50).size();
	}
	
	public int getCountByCatalogId(String catalogId) throws Exception{
		return mdd.selectPartLimitToMap("{\"cid\":\"" + catalogId + "\"}",50).size();
	}
	
	public boolean update(Map<String, Object> searchMap,Map<String, Object> updateMap) throws Exception{
		return  mdd.update(searchMap, updateMap).isUpdateOfExisting();
	}
	
	public boolean update(String catalogId,Map<String, Object> updateMap) throws Exception{
		return  mdd.update(MapUtil.hashMap("cid",catalogId), updateMap).isUpdateOfExisting();
	}
	
	public static void main(String arg[]) throws Exception{
		Map<String,Object> aa = new CatalogsWapper().getByCatalogId("44999897-46e5-406c-a556-be3e052cc14a");
		
		
		int c=1;
		int a=c;
	}
	
}
